***************************************************************************************
*** Replication code for "State Repression and Opposition Survival in Pinochet's Chile"
*** by Consuelo Amat 
*** CPS, January 2023
*********************

*** APPENDIX ***

** Software and version: STATA 17.0

** Load Data
clear all
cd "~/directory" // fill in
insheet using "sequence_captures.csv"

**Install programs
ssc install rangestat


*Figure 3

*Adding survival model structure to data:
gen date_mdy = mdy(month_detention, day_detention, year_detention)
gen date_mdy2 = mdy(month_detention, day_detention, year_detention)
format date_mdy2 %td
stset date_mdy 

*Calculate average number of captures in a 30-day period:

gen obs = .
replace obs = 1 if orgid!=.
summ obs

sort year_detention month_detention day_detention

rangestat (sum) sum_speed_detention=obs, interval(date_mdy 0 30) by(orgid) 
gen speed_detention=.
replace speed_detention= sum_speed_detention/30

*Create variables to compare MIR to PS, and MIR to PC:
gen mir_vs_ps = .
replace mir_vs_ps=1 if orgid==101
replace mir_vs_ps=0 if orgid==132

gen mir_vs_pc = .
replace mir_vs_pc=1 if orgid==101
replace mir_vs_pc=0 if orgid==131

*Plot:
twoway (histogram date_mdy2 if date_mdy>5001 & date_mdy<6199, freq discrete by(mir_vs_ps) yaxis(1)) ///
	   (line speed_detention date_mdy2 if date_mdy>5001 & date_mdy<6199, by(mir_vs_ps) yaxis(2) lpattern(dash) lwidth(medium) lcolor(blue)) 
	   
	   
*Figure 4

*Calculate average number of captures in a 60-day period:

rangestat (sum) sum_speed_detention60=obs, interval(date_mdy 0 60) by(orgid) 
gen speed_detention60 =.
replace speed_detention60= sum_speed_detention60/60

*Plot:
twoway (histogram date_mdy2 if date_mdy>5001 & date_mdy<6199, freq discrete by(mir_vs_ps) yaxis(1)) ///
	   (line speed_detention60 date_mdy2 if date_mdy>5001 & date_mdy<6199, by(mir_vs_ps) yaxis(2) lpattern(dash) lwidth(medium) lcolor(blue)) 

	   
*Figure 5

*Plot:
twoway (histogram date_mdy2 if date_mdy>5001 & date_mdy<6199, freq discrete by(mir_vs_pc) yaxis(1)) ///
	   (line speed_detention60 date_mdy2 if date_mdy>5001 & date_mdy<6199, by(mir_vs_pc) yaxis(2) lpattern(dash) lwidth(medium) lcolor(blue)) 
	   

*Figure 6
**OLS models for plot:
*Comparing MIR vs. PS and PC: Sept 11, 1973-1976, inclusive
regress speed_detention60 mir region_n if (date_mdy>5001 & date_mdy<6199)  
estimates store Sept1173_Dec76MIR60
*Comparing MIR vs. PS and PC: whole period 
regress speed_detention60 mir region_n 
estimates store wholeperiodMIR60
*Comparing MIR vs. PS: Sept 11, 1973-1976, inclusive 
regress speed_detention60 mir_vs_ps region_n if (date_mdy>5001 & date_mdy<6199) 
estimates store Sept1173_Dec76MIRPS60
*Comparing MIR vs. PS: whole period 
regress speed_detention60 mir_vs_ps region_n 
estimates store wholeperiodMIRPS60
*Comparing MIR vs. PC: Sept 11, 1973-1976, inclusive 
regress speed_detention60 mir_vs_pc region_n if (date_mdy>5001 & date_mdy<6199) 
estimates store Sept1173_Dec76MIRPC60
*Comparing MIR vs. PC: whole period 
regress speed_detention60 mir_vs_pc region_n 
estimates store wholeperiodMIRPC60

*Plot main coefficients from all models:
coefplot Sept1173_Dec76MIR60 wholeperiodMIR60 Sept1173_Dec76MIRPS60 wholeperiodMIRPS60 Sept1173_Dec76MIRPC60 wholeperiodMIRPC60, horizontal xline(0) drop(_cons) 

	   
*Figure 7

*Plot:
twoway (histogram date_mdy2 if date_mdy>5001 & date_mdy<6199, freq discrete by(mir_vs_pc) yaxis(1)) ///
	   (line speed_detention date_mdy2 if date_mdy>5001 & date_mdy<6199, by(mir_vs_pc) yaxis(2) lpattern(dash) lwidth(medium) lcolor(blue)) 
	  
	   
*Figure 8

twoway (histogram date_mdy2 if date_mdy>5113 & date_mdy<6199, freq discrete by(mir_vs_ps) yaxis(1)) ///
	   (line speed_detention date_mdy2 if date_mdy>5113 & date_mdy<6199, by(mir_vs_ps) yaxis(2) lpattern(dash) lwidth(medium) lcolor(blue)) 

	   
*Figure 9

twoway (histogram date_mdy2 if date_mdy>5113 & date_mdy<6199, freq discrete by(mir_vs_pc) yaxis(1)) ///
	   (line speed_detention date_mdy2 if date_mdy>5113 & date_mdy<6199, by(mir_vs_pc) yaxis(2) lpattern(dash) lwidth(medium) lcolor(blue)) 
	   
	   

*Figure 10
**OLS models for plot:
*Comparing MIR vs. PS and PC: Sept 11, 1973-1976, inclusive
regress speed_detention mir region_n if (date_mdy>5001 & date_mdy<6199)
estimates store Sept1173_Dec76MIR
*Comparing MIR vs. PS and PC: whole period
regress speed_detention mir region_n 
estimates store wholeperiodMIR
*Comparing MIR vs. PS and PC: Jan 1, 1974 and beyond, inclusive
regress speed_detention mir region_n if date_mdy>5113 
estimates store Post1973MIR
*Comparing MIR vs. PS and PC: Jan 1, 1974 to 1976, inclusive
regress speed_detention mir region_n if (date_mdy>5113 & date_mdy<6199)  
estimates store Btw74_76MIR

*Plot main coefficients from all models:
coefplot Sept1173_Dec76MIR wholeperiodMIR Post1973MIR Btw74_76MIR, horizontal xline(0) drop(_cons)



